<template>
    <div>
        <div class="chima-box table-form">
            <div class="table-title table-title-btn">
                <el-space wrap>
                    <el-button
                        :disabled="isEditing"
                        type="primary"
                        @click="generateParam1"
                    >
                        新增眼型
                    </el-button>
                    <el-button
                        :disabled="isEditing"
                        type="primary"
                        @click="generateParam2"
                    >
                        新增脾型
                    </el-button>
                    <el-button
                        :disabled="isEditing"
                        type="danger"
                        @click="delAll"
                        >删除</el-button
                    >
                </el-space>
            </div>
            <el-table
                :data="props.yanPiData"
                @selection-change="handleSelectionChange"
                style="width: 100%"
                border
                :row-class-name="tableRowClassName"
            >
                <el-table-column type="selection" width="55" />
                <el-table-column prop="eyeNum" label="眼型编号">
                </el-table-column>
                <el-table-column prop="tempTypeNum" label="临时编号">
                </el-table-column>
                <el-table-column prop="spleenNum" label="脾型编号">
                </el-table-column>
                <el-table-column prop="hardMoldNum" label="硬模编号">
                </el-table-column>
                <el-table-column prop="spleenType" label="脾型类型">
                </el-table-column>

                <el-table-column prop="sizeNum" label="关联尺码">
                </el-table-column>
                <el-table-column
                    prop="op"
                    label="操作"
                    width="150"
                    v-if="!isEditing"
                >
                    <template #default="{ row, $index }">
                        <a
                            href="javascript:"
                            @click.prevent="editRow(row)"
                            style="margin-right: 10px"
                            >编辑</a
                        >
                        <a href="javascript:" @click.prevent="deleteRow($index)"
                            >删除</a
                        >
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <!-- 眼型脾型弹窗 -->
        <!-- <el-dialog
            v-model="yanPiDialogshow"
            destroy-on-close
            title="眼型脾型"
            width="700"
        >
            <el-tabs
                v-model="yanPiActiveName"
                type="card"
                class="demo-tabs"
                @tab-change="tabChange"
            >
                <el-tab-pane label="眼型参数" name="yan">
                    <el-form
                        :model="yanPiDialogData"
                        ref="formEl1"
                        :rules="yanPiDialogRule"
                    >
                        <el-row>
                            <el-col :span="8">
                                <el-form-item label="眼型编号:">
                                    <el-radio-group
                                        v-model="yanPiDialogData.eyeNumType"
                                        @change="
                                            (val) => {
                                                oldOrNewChange(
                                                    val,
                                                    'eyeNumType'
                                                );
                                            }
                                        "
                                    >
                                        <el-radio :value="1">旧</el-radio>
                                        <el-radio :value="2">新</el-radio>
                                    </el-radio-group>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item
                                    label=""
                                    v-if="yanPiDialogData.eyeNumType == 1"
                                    prop="eyeNumOld"
                                >
                                    <el-input
                                        v-model="yanPiDialogData.eyeNumOld"
                                        placeholder="请输入旧眼型编号"
                                    />
                                </el-form-item>
                                <el-form-item
                                    label=""
                                    v-if="yanPiDialogData.eyeNumType == 2"
                                    prop="eyeNumNew"
                                >
                                    <div style="display: flex">
                                        <el-input
                                            v-model="yanPiDialogData.eyeNumNew"
                                            placeholder=""
                                            disabled
                                        />
                                        <el-button
                                            type="primary"
                                            style="margin-left: 20px"
                                            @click="getEyeDataFun"
                                            :disabled="
                                                !!yanPiDialogData.eyeNumNew
                                            "
                                            >生成新</el-button
                                        >
                                    </div>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="关联尺码:" prop="sizeNum">
                                    <el-checkbox-group
                                        v-model="yanPiDialogData.sizeNum"
                                        v-if="sizeData.length > 0"
                                    >
                                        <el-checkbox
                                            v-for="item in sizeData"
                                            :key="item.sizeNum"
                                            :label="item.sizeNum"
                                            :value="item.sizeNum"
                                            >{{ item.sizeNum }}</el-checkbox
                                        >
                                    </el-checkbox-group>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                </el-tab-pane>
                <el-tab-pane label="脾型参数" name="pi">
                    <el-form
                        :model="yanPiDialogData"
                        ref="formEl2"
                        class="yanpidia"
                        :rules="yanPiDialogRule"
                    >
                        <el-row>
                            <el-col :span="10">
                                <el-form-item label="临时编号:">
                                    <el-radio-group
                                        v-model="
                                            yanPiDialogData.tempTypeNumType
                                        "
                                        @change="
                                            (val) => {
                                                oldOrNewChange(
                                                    val,
                                                    'tempTypeNumType'
                                                );
                                            }
                                        "
                                    >
                                        <el-radio :value="1">旧</el-radio>
                                        <el-radio :value="2">新</el-radio>
                                    </el-radio-group>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item
                                    label=""
                                    v-if="yanPiDialogData.tempTypeNumType == 1"
                                    prop="tempTypeNumOld"
                                >
                                    <el-input
                                        v-model="yanPiDialogData.tempTypeNumOld"
                                        placeholder="请输入旧临时编号"
                                    />
                                </el-form-item>
                                <el-form-item
                                    label=""
                                    v-if="yanPiDialogData.tempTypeNumType == 2"
                                    prop="tempTypeNumNew"
                                >
                                    <div style="display: flex">
                                        <el-input
                                            v-model="
                                                yanPiDialogData.tempTypeNumNew
                                            "
                                            placeholder=""
                                            disabled
                                        />
                                        <el-button
                                            type="primary"
                                            style="margin-left: 20px"
                                            @click="getFirstOrderNumFun"
                                            :disabled="
                                                !!yanPiDialogData.tempTypeNumNew
                                            "
                                            >生成新</el-button
                                        >
                                    </div>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="10">
                                <el-form-item label="脾型编号:">
                                    <el-radio-group
                                        v-model="yanPiDialogData.spleenNumType"
                                        @change="
                                            (val) => {
                                                oldOrNewChange(
                                                    val,
                                                    'spleenNumType'
                                                );
                                            }
                                        "
                                    >
                                        <el-radio :value="1">旧</el-radio>
                                        <el-radio :value="2">新</el-radio>
                                    </el-radio-group>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item
                                    label=""
                                    v-if="yanPiDialogData.spleenNumType == 1"
                                    prop="spleenNumOld"
                                >
                                    <el-input
                                        v-model="yanPiDialogData.spleenNumOld"
                                        placeholder="请输入旧脾型编号"
                                    />
                                </el-form-item>
                                <el-form-item
                                    label=""
                                    v-if="yanPiDialogData.spleenNumType == 2"
                                    prop="spleenNumNew"
                                >
                                    <div style="display: flex">
                                        <el-input
                                            v-model="
                                                yanPiDialogData.spleenNumNew
                                            "
                                            placeholder=""
                                            disabled
                                        />
                                        <el-button
                                            type="primary"
                                            style="margin-left: 20px"
                                            @click="getSpleenDataFun"
                                            :disabled="
                                                !!yanPiDialogData.spleenNumNew
                                            "
                                            >生成新</el-button
                                        >
                                    </div>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="10">
                                <el-form-item label="硬模编号:">
                                    <el-radio-group
                                        v-model="yanPiDialogData.hardMoldType"
                                        @change="
                                            (val) => {
                                                oldOrNewChange(
                                                    val,
                                                    'hardMoldType'
                                                );
                                            }
                                        "
                                    >
                                        <el-radio :value="3">无</el-radio>
                                        <el-radio :value="1">旧</el-radio>
                                        <el-radio :value="2">新</el-radio>
                                    </el-radio-group>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item
                                    label=""
                                    v-if="yanPiDialogData.hardMoldType == 1"
                                    prop="hardMoldNumOld"
                                >
                                    <el-input
                                        v-model="yanPiDialogData.hardMoldNumOld"
                                        placeholder="请输入旧硬模编号"
                                    />
                                </el-form-item>
                                <el-form-item
                                    label=""
                                    v-if="yanPiDialogData.hardMoldType == 2"
                                    prop="hardMoldNumNew"
                                >
                                    <div style="display: flex">
                                        <el-input
                                            v-model="
                                                yanPiDialogData.hardMoldNumNew
                                            "
                                            placeholder=""
                                            disabled
                                        />
                                        <el-button
                                            type="primary"
                                            style="margin-left: 20px"
                                            @click="getHardMoldNumFun"
                                            :disabled="
                                                !!yanPiDialogData.hardMoldNumNew
                                            "
                                            >生成新</el-button
                                        >
                                    </div>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-form-item label="关联尺码:" prop="sizeNum">
                                <el-checkbox-group
                                    v-model="yanPiDialogData.sizeNum"
                                    v-if="sizeData.length > 0"
                                >
                                    <el-checkbox
                                        v-for="item in sizeData"
                                        :key="item.sizeNum"
                                        :label="item.sizeNum"
                                        :value="item.sizeNum"
                                        >{{ item.sizeNum }}</el-checkbox
                                    >
                                </el-checkbox-group>
                            </el-form-item>
                        </el-row>
                    </el-form>
                </el-tab-pane>
            </el-tabs>

            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="handleClose">
                        确定
                    </el-button>
                </div>
            </template>
        </el-dialog> -->
        <el-dialog
            v-model="yanDialogshow"
            destroy-on-close
            title="眼型参数"
            width="700"
        >
            <el-form
                :model="yanPiDialogData"
                ref="formEl1"
                :rules="yanPiDialogRule"
            >
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="眼型编号:">
                            <el-radio-group
                                v-model="yanPiDialogData.eyeNumType"
                                @change="
                                    (val) => {
                                        oldOrNewChange(val, 'eyeNumType');
                                    }
                                "
                            >
                                <el-radio :value="1">旧</el-radio>
                                <el-radio :value="2">新</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item
                            label=""
                            v-if="yanPiDialogData.eyeNumType == 1"
                            prop="eyeNumOld"
                        >
                            <el-input
                                v-model="yanPiDialogData.eyeNumOld"
                                placeholder="请输入旧眼型编号"
                            />
                        </el-form-item>
                        <el-form-item
                            label=""
                            v-if="yanPiDialogData.eyeNumType == 2"
                            prop="eyeNumNew"
                        >
                            <div style="display: flex">
                                <el-input
                                    v-model="yanPiDialogData.eyeNumNew"
                                    placeholder=""
                                    disabled
                                />
                                <el-button
                                    type="primary"
                                    style="margin-left: 20px"
                                    @click="getEyeDataFun"
                                    :disabled="!!yanPiDialogData.eyeNumNew"
                                    >生成新</el-button
                                >
                            </div>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="关联尺码:" prop="sizeNum">
                            <el-checkbox-group
                                v-model="yanPiDialogData.sizeNum"
                                v-if="sizeData.length > 0"
                            >
                                <el-checkbox
                                    v-for="item in sizeData"
                                    :key="item.sizeNum"
                                    :label="item.sizeNum"
                                    :value="item.sizeNum"
                                    >{{ item.sizeNum }}</el-checkbox
                                >
                            </el-checkbox-group>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="handleClose">
                        确定
                    </el-button>
                </div>
            </template>
        </el-dialog>
        <el-dialog
            v-model="piDialogshow"
            destroy-on-close
            title="脾型参数"
            width="700"
        >
            <el-form
                :model="yanPiDialogData"
                ref="formEl2"
                class="yanpidia"
                :rules="yanPiDialogRule"
            >
                <!-- 首办参考编号 -->
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="临时编号:">
                            <el-radio-group
                                v-model="yanPiDialogData.tempTypeNumType"
                                @change="
                                    (val) => {
                                        oldOrNewChange(val, 'tempTypeNumType');
                                    }
                                "
                            >
                                <el-radio :value="1">旧</el-radio>
                                <el-radio :value="2">新</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item
                            label=""
                            v-if="yanPiDialogData.tempTypeNumType == 1"
                            prop="tempTypeNumOld"
                        >
                            <el-input
                                v-model="yanPiDialogData.tempTypeNumOld"
                                placeholder="请输入旧临时编号"
                            />
                        </el-form-item>
                        <el-form-item
                            label=""
                            v-if="yanPiDialogData.tempTypeNumType == 2"
                            prop="tempTypeNumNew"
                        >
                            <div style="display: flex">
                                <el-input
                                    v-model="yanPiDialogData.tempTypeNumNew"
                                    placeholder=""
                                    disabled
                                />
                                <el-button
                                    type="primary"
                                    style="margin-left: 20px"
                                    @click="getFirstOrderNumFun"
                                    :disabled="!!yanPiDialogData.tempTypeNumNew"
                                    >生成新</el-button
                                >
                            </div>
                        </el-form-item>
                    </el-col>
                </el-row>
                <!-- 正式脾型编号 -->
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="脾型编号:">
                            <el-radio-group
                                v-model="yanPiDialogData.spleenNumType"
                                @change="
                                    (val) => {
                                        oldOrNewChange(val, 'spleenNumType');
                                    }
                                "
                            >
                                <el-radio :value="1">旧</el-radio>
                                <el-radio :value="2">新</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item
                            label=""
                            v-if="yanPiDialogData.spleenNumType == 1"
                            prop="spleenNumOld"
                        >
                            <el-input
                                v-model="yanPiDialogData.spleenNumOld"
                                placeholder="请输入旧脾型编号"
                            />
                        </el-form-item>
                        <el-form-item
                            label=""
                            v-if="yanPiDialogData.spleenNumType == 2"
                            prop="spleenNumNew"
                        >
                            <div style="display: flex">
                                <el-input
                                    v-model="yanPiDialogData.spleenNumNew"
                                    placeholder=""
                                    disabled
                                />
                                <el-button
                                    type="primary"
                                    style="margin-left: 20px"
                                    @click="getSpleenDataFun"
                                    :disabled="!!yanPiDialogData.spleenNumNew"
                                    >生成新</el-button
                                >
                            </div>
                        </el-form-item>
                    </el-col>
                </el-row>
                <!-- 硬模编号 -->
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="硬模编号:">
                            <el-radio-group
                                v-model="yanPiDialogData.hardMoldType"
                                @change="
                                    (val) => {
                                        oldOrNewChange(val, 'hardMoldType');
                                    }
                                "
                            >
                                <el-radio :value="3">无</el-radio>
                                <el-radio :value="1">旧</el-radio>
                                <el-radio :value="2">新</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item
                            label=""
                            v-if="yanPiDialogData.hardMoldType == 1"
                            prop="hardMoldNumOld"
                        >
                            <el-input
                                v-model="yanPiDialogData.hardMoldNumOld"
                                placeholder="请输入旧硬模编号"
                            />
                        </el-form-item>
                        <el-form-item
                            label=""
                            v-if="yanPiDialogData.hardMoldType == 2"
                            prop="hardMoldNumNew"
                        >
                            <div style="display: flex">
                                <el-input
                                    v-model="yanPiDialogData.hardMoldNumNew"
                                    placeholder=""
                                    disabled
                                />
                                <el-button
                                    type="primary"
                                    style="margin-left: 20px"
                                    @click="getHardMoldNumFun"
                                    :disabled="!!yanPiDialogData.hardMoldNumNew"
                                    >生成新</el-button
                                >
                            </div>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-form-item label="关联尺码:" prop="sizeNum">
                        <el-checkbox-group
                            v-model="yanPiDialogData.sizeNum"
                            v-if="sizeData.length > 0"
                        >
                            <el-checkbox
                                v-for="item in sizeData"
                                :key="item.sizeNum"
                                :label="item.sizeNum"
                                :value="item.sizeNum"
                                >{{ item.sizeNum }}</el-checkbox
                            >
                        </el-checkbox-group>
                    </el-form-item>
                </el-row>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="handleClose">
                        确定
                    </el-button>
                </div>
            </template>
        </el-dialog>
    </div>
</template>

<script setup>
import {
    reactive,
    ref,
    toRefs,
    defineProps,
    computed,
    onMounted,
    defineEmits,
    nextTick,
} from "vue";
import { ElMessage, ElMessageBox, ElNotification } from "element-plus";
import {
    getEyeData,
    getFirstOrderNum,
    getSpleenData,
    getHardMoldNum,
    updateSpleenNumber,
} from "@/api/plmProductSpec.js";
import { getEyeNumberDocumentList } from "@/api/confEyeNumberDocument";
import { getSpleenNumberList } from "@/api/confSpleenNumber";
import { deepClone2, debounce } from "@/utils/tool.js";
import { emitter } from "@/utils/bus.js";
import { useRoute, useRouter } from "vue-router";
// 使用 useRoute 函数获取当前路由信息
const router = new useRouter();
const route = new useRoute();

let robot = ref(null);

const props = defineProps({
    sizeData: {
        type: Array,
        default: [],
    },
    yanPiData: {
        type: Array,
        default: [],
    },
    isEditing: { type: Boolean, default: false },
});
const emit = defineEmits(["update:yanPiData"]);
const sizeData = computed(() => {
    let list = props.sizeData.filter((item) => {
        return !!item.sizeNum;
    });
    return deepClone2(list);
});

// 眼型脾型参数start-----------------------
// const yanPiData = ref([
//     // {
//     //     eyeNum: "", // 眼型编号
//     //     spleenNum: "", // 脾型编号
//     //     tempTypeNum: "", // 临时编号
//     //     hardMoldNum: "", // 硬模编号
//     //     spleenType: "", // 脾型编号
//     //     sizeNum: "", // 关联尺码
//     // },
// ]);
// 弹窗显示隐藏
const yanPiDialogshow = ref(false);
const yanDialogshow = ref(false);
const piDialogshow = ref(false);
// 弹窗数据
const yanPiDialogData = ref({
    eyeNumType: 1, // 眼型编号类型（新/旧）
    tempTypeNumType: 1, // 首办参考编号（新/旧） --- 临时
    spleenNumType: 1, // 硬膜编号（新/旧）
    hardMoldType: 1, // 正式脾型编号（新/旧/无）
    sizeNum: [],
});
const yanPiActiveName = ref("yan");
const formEl1 = ref();
const formEl2 = ref();
const yanPiDialogRule = ref({
    sizeNum: [
        {
            required: true,
            message: "请关联尺码",
            trigger: "change",
        },
    ],
    eyeNumType: [
        {
            required: true,
            message: "请选择",
            trigger: "change",
        },
    ],
    eyeNumOld: [
        {
            required: true,
            message: "编号不能为空",
            trigger: "change",
        },
    ],
    eyeNumNew: [
        {
            required: true,
            message: "编号不能为空",
            trigger: "change",
        },
    ],
});

const eyeNumOldOptions = ref([]); //旧眼型编号选择列表
const hardMoldNumOldOptions = ref([]); //旧硬模编号选择列表
const spleenNumOldOptions = ref([]); //旧正式脾型编号选择列表
const tempTypeNumOldOptions = ref([]); //旧首办参考编号选择列表
// end-----------------------

// defineExpose({ yanPiData });

// 打开生成参数弹窗
const generateParam = (params) => {
    // 初始化参数
    yanPiActiveName.value = "yan";
    yanPiDialogData.value = {
        eyeNumType: 1, // 眼型编号类型（新/旧）
        tempTypeNumType: 1, // 首办参考编号（新/旧） --- 临时
        spleenNumType: 1, // 硬膜编号（新/旧）
        hardMoldType: 1, // 正式脾型编号（新/旧/无）
        tempTypeNumOld: "",
        tempTypeNumNew: "",
        spleenNumOld: "",
        spleenNumNew: "",
        hardMoldNumOld: "",
        hardMoldNumNew: "",
        sizeNum: [],
    };
    yanDialogshow.value = true;
};
const generateParam1 = (params) => {
    // 初始化参数
    yanPiActiveName.value = "yan";
    yanPiDialogData.value = {
        eyeNumType: 1, // 眼型编号类型（新/旧）
        tempTypeNumType: 1, // 首办参考编号（新/旧） --- 临时
        spleenNumType: 1, // 硬膜编号（新/旧）
        hardMoldType: 1, // 正式脾型编号（新/旧/无）
        tempTypeNumOld: "",
        tempTypeNumNew: "",
        spleenNumOld: "",
        spleenNumNew: "",
        hardMoldNumOld: "",
        hardMoldNumNew: "",
        sizeNum: [],
    };
    yanDialogshow.value = true;
};
const generateParam2 = (params) => {
    // 初始化参数
    yanPiActiveName.value = "pi";
    yanPiDialogData.value = {
        eyeNumType: 1, // 眼型编号类型（新/旧）
        tempTypeNumType: 1, // 首办参考编号（新/旧） --- 临时
        spleenNumType: 1, // 硬膜编号（新/旧）
        hardMoldType: 1, // 正式脾型编号（新/旧/无）
        tempTypeNumOld: "",
        tempTypeNumNew: "",
        spleenNumOld: "",
        spleenNumNew: "",
        hardMoldNumOld: "",
        hardMoldNumNew: "",
        sizeNum: [],
    };
    piDialogshow.value = true;
};
// tabs改变
const tabChange = (key) => {
    console.log("key", key);
    // if (key == "pi") {
    yanPiDialogData.value["eyeNumType"] = 1; // 眼型编号类型（新/旧）
    yanPiDialogData.value["eyeNumOld"] = "";
    yanPiDialogData.value["eyeNumNew"] = "";
    // }
    // if (key == "yan") {
    yanPiDialogData.value["tempTypeNumType"] = 1; // 首办参考编号（新/旧） --- 临时
    yanPiDialogData.value["spleenNumType"] = 1; // 硬膜编号（新/旧）
    yanPiDialogData.value["hardMoldType"] = 1; // 正式脾型编号（新/旧/无）
    yanPiDialogData.value["tempTypeNumOld"] = "";
    yanPiDialogData.value["tempTypeNumNew"] = "";
    yanPiDialogData.value["spleenNumOld"] = "";
    yanPiDialogData.value["spleenNumNew"] = "";
    yanPiDialogData.value["hardMoldNumOld"] = "";
    yanPiDialogData.value["hardMoldNumNew"] = "";
    // }
    if (yanPiDialogData.value.ida) {
        yanPiDialogData.value["ida"] = yanPiDialogData.value.ida;
    }
};
// 删除一行
const deleteRow = (index) => {
    ElMessageBox.confirm("确定要删除吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
    }).then(() => {
        let list = deepClone2(props.yanPiData);
        list.splice(index, 1);
        emit("update:yanPiData", list);
    });
};
// 编辑行
const editRow = (row) => {
    if (!!row.numSet) {
        yanPiDialogData.value = row.numSet;
    } else {
        yanPiDialogData.value = {
            eyeNumType: 1, // 眼型编号类型（新/旧）
            tempTypeNumType: 1, // 首办参考编号（新/旧） --- 临时
            spleenNumType: 1, // 硬膜编号（新/旧）
            hardMoldType: 1, // 正式脾型编号（新/旧/无）
            tempTypeNumOld: row.tempTypeNum || "",
            tempTypeNumNew: "",
            spleenNumOld: row.spleenNum || "",
            spleenNumNew: "",
            hardMoldNumOld: row.hardMoldNum || "",
            hardMoldNumNew: "",
            eyeNumOld: row.eyeNum || "",
            eyeNumNew: "",
            sizeNum: row.sizeNum ? row.sizeNum.split(",") : [],
        };
    }
    yanPiDialogData.value["ida"] = row.ida;
    yanPiActiveName.value = row.eyeNum ? "yan" : "pi";
    if (!row.eyeNum) {
        piDialogshow.value = true;
    } else {
        yanDialogshow.value = true;
    }
};

// 眼型脾型多选,批量操作
//row-class-name添加下标
const multipleSelection = ref([]);
const selectlistRow = ref([]);
const tableRowClassName = (row, index) => {
    row.row.index = row.rowIndex;
};
const handleSelectionChange = (val) => {
    multipleSelection.value = val;
    selectlistRow.value = val;
};
const delAll = () => {
    ElMessageBox.confirm("确定要删除吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
    }).then(() => {
        let list = deepClone2(props.yanPiData);
        multipleSelection.value.forEach((item) => {
            list = list.filter((items) => items.index !== item.index);
        });
        emit("update:yanPiData", list);
    });
};

// 获取眼型编号
const getEyeDataFun = () => {
    if (!!yanPiDialogData.value.eyeNumNew) return;
    getEyeData().then((res) => {
        if (res.code === 0) {
            yanPiDialogData.value.eyeNumNew = res.data.eyeNum;
        }
    });
};
// 获取首办参考编号
const getFirstOrderNumFun = () => {
    if (!!yanPiDialogData.value.tempTypeNumNew) return;
    let params = {
        stampingDie: yanPiDialogData.value.spleenNumNew,
        hardMoldStampingDie: yanPiDialogData.value.hardMoldNumNew,
    };
    getFirstOrderNum(params).then((res) => {
        if (res.code === 0) {
            yanPiDialogData.value["tempTypeNumNew"] = res.data.firstOrderNum;
        }
    });
};
// 获取脾型编号
const getSpleenDataFun = () => {
    if (!!yanPiDialogData.value.spleenNumNew) return;
    let params = {
        firstOrderNum: yanPiDialogData.value.tempTypeNumNew,
        hardMoldStampingDie: yanPiDialogData.value.hardMoldNumNew,
    };
    getSpleenData(params).then((res) => {
        if (res.code === 0) {
            yanPiDialogData.value["spleenNumNew"] = res.data.spleenNum;
        }
    });
};
const hardMoldNumNewId = ref(0);
//  获取硬模编号
const getHardMoldNumFun = () => {
    let stampingDie =
        yanPiDialogData.value.spleenNumNew ||
        yanPiDialogData.value.spleenNumOld;
    if (!stampingDie) {
        // ElMessage({ type: "error", offset: "25", message: "请先填写脾型编号" });
        ElNotification({
            title: "请先填写脾型编号",
            type: "error",
            position: "bottom-left",
            customClass: "notification-item-err",
        });
        return;
    }
    let params = {
        cncMachining: stampingDie,
    };
    getHardMoldNum(params).then((res) => {
        if (res.code === 0) {
            yanPiDialogData.value["hardMoldNumNew"] = res.data.hardMoldNum;
            hardMoldNumNewId.value = res.data.ID;
        }
    });
};
// 弹窗确定
const handleClose = async () => {
    if (yanPiActiveName.value == "yan") {
        if (!formEl1.value) return;
        formEl1.value.validate((valid) => {
            if (!valid) {
                return false;
            }
            let { eyeNumType, eyeNumNew, eyeNumOld, sizeNum } =
                yanPiDialogData.value;
            let list = deepClone2(props.yanPiData);
            if (yanPiDialogData.value.ida) {
                let index = list.findIndex((m) => {
                    return m.ida == yanPiDialogData.value.ida;
                });
                if (index != -1) {
                    list[index]["eyeNum"] =
                        eyeNumType == 1 ? eyeNumOld : eyeNumNew;
                    list[index]["ida"] = yanPiDialogData.value.ida;
                    list[index]["tempTypeNum"] = "";
                    list[index]["spleenNum"] = "";
                    list[index]["hardMoldNum"] = "";
                    list[index]["sizeNum"] = sizeNum && sizeNum.join(",");
                    list[index]["spleenType"] = "";
                    list[index]["numSet"] = deepClone2(yanPiDialogData.value);
                }
            } else {
                list.push({
                    eyeNum: eyeNumType == 1 ? eyeNumOld : eyeNumNew,
                    sizeNum: sizeNum && sizeNum.join(","),
                    tempTypeNum: "", // 首办参考编号
                    spleenNum: "", // 正式脾型编号
                    hardMoldNum: "", //硬模编号
                    numSet: deepClone2(yanPiDialogData.value),
                    ida: new Date().getTime(),
                });
            }

            emit("update:yanPiData", deepClone2(list));
            yanPiDialogshow.value = false;
            yanDialogshow.value = false;
        });
    }
    if (yanPiActiveName.value == "pi") {
        if (!formEl2.value) return;
        formEl2.value.validate(async (valid) => {
            if (!valid) {
                console.log("error submit!");
                return false;
            }
            let {
                tempTypeNumType,
                tempTypeNumOld,
                tempTypeNumNew,
                spleenNumType,
                spleenNumOld,
                spleenNumNew,
                hardMoldType,
                hardMoldNumOld,
                hardMoldNumNew,
                sizeNum,
            } = yanPiDialogData.value;
            let list = deepClone2(props.yanPiData);
            let res = null;
            if (
                tempTypeNumType == 2 ||
                spleenNumType == 2 ||
                hardMoldType == 2
            ) {
                let params1 = {
                    firstOrderNum: tempTypeNumNew,
                    cncMachining: spleenNumNew,
                    hardMoldCnc: hardMoldNumNew,
                };
                if (hardMoldNumNew) {
                    params1["ID"] = hardMoldNumNewId.value;
                }
                res = await updateSpleenNumber(params1);
                if (res.code != 0) return;
            }
            if (yanPiDialogData.value.ida) {
                let index = list.findIndex((m) => {
                    return m.ida == yanPiDialogData.value.ida;
                });
                if (index != -1) {
                    list[index]["eyeNum"] = "";
                    list[index]["ida"] = yanPiDialogData.value.ida;
                    list[index]["tempTypeNum"] =
                        tempTypeNumType == 1 ? tempTypeNumOld : tempTypeNumNew;
                    list[index]["spleenNum"] =
                        spleenNumType == 1 ? spleenNumOld : spleenNumNew;
                    list[index]["hardMoldNum"] =
                        hardMoldType == 1
                            ? hardMoldNumOld
                            : hardMoldType == 2
                            ? hardMoldNumNew
                            : "";
                    list[index]["sizeNum"] = sizeNum && sizeNum.join(",");
                    list[index]["spleenType"] = "CNC";
                    list[index]["numSet"] = deepClone2(yanPiDialogData.value);
                }
            } else {
                list.push({
                    tempTypeNum:
                        tempTypeNumType == 1 ? tempTypeNumOld : tempTypeNumNew,
                    spleenNum: spleenNumType == 1 ? spleenNumOld : spleenNumNew,
                    hardMoldNum:
                        hardMoldType == 1
                            ? hardMoldNumOld
                            : hardMoldType == 2
                            ? hardMoldNumNew
                            : "",
                    sizeNum: sizeNum && sizeNum.join(","),
                    spleenType: "CNC",
                    numSet: deepClone2(yanPiDialogData.value),
                    ida: new Date().getTime(),
                });
            }
            emit("update:yanPiData", deepClone2(list));
            yanPiDialogshow.value = false;
            piDialogshow.value = false;
        });
    }
};

// 获取眼型编号主档列表
const getEyeNumberDocumentListFun = async (keyword) => {
    const table = await getEyeNumberDocumentList({
        page: 1,
        pageSize: 50,
        keyword: keyword,
    });
    if (table.code === 0) {
        eyeNumOldOptions.value = table.data.list
            .filter((res) => {
                return res.officialNum;
            })
            .map((item) => {
                return { label: item.officialNum, value: item.officialNum };
            });
    }
};

// 新旧切换
const oldOrNewChange = (val, type) => {
    console.log(val, type);
    switch (type) {
        case "eyeNumType":
            if (val == 1) {
                yanPiDialogData.value.eyeNumNew = "";
            } else if (val == 2) {
                yanPiDialogData.value.eyeNumOld = "";
            }
            break;
        case "tempTypeNumType":
            if (val == 1) {
                yanPiDialogData.value.tempTypeNumNew = "";
            } else if (val == 2) {
                yanPiDialogData.value.tempTypeNumOld = "";
            }
            break;
        case "spleenNumType":
            if (val == 1) {
                yanPiDialogData.value.spleenNumNew = "";
            } else if (val == 2) {
                yanPiDialogData.value.spleenNumOld = "";
            }
            break;
        case "hardMoldType":
            hardMoldNumNewId.value = 0;
            if (val == 1) {
                yanPiDialogData.value.hardMoldNumNew = "";
            } else if (val == 2) {
                yanPiDialogData.value.hardMoldNumOld = "";
            } else if (val == 3) {
                yanPiDialogData.value.hardMoldNumNew = "";
                yanPiDialogData.value.hardMoldNumOld = "";
            }
            break;
    }
};

onMounted(() => {
    // 修改尺码，所关联值同步修改
    emitter.on("sizeChangeFun", (sizeChangeVal) => {
        let list = deepClone2(props.yanPiData);
        if (sizeChangeVal.type == "edit") {
            list.forEach((item) => {
                let sizeNumList = item.sizeNum.split(",");
                let index = sizeNumList.findIndex((res) => {
                    return res == sizeChangeVal.sizeOld;
                });
                if (index != -1) {
                    sizeNumList[index] = sizeChangeVal.sizeNew;
                }
                item.sizeNum = sizeNumList.join(",");
            });
        } else if (sizeChangeVal.type == "del") {
            list.forEach((item) => {
                if (item.sizeNum) {
                    let list = item.sizeNum.split(",");
                    list = list.filter((res) => {
                        return res != sizeChangeVal.sizeOld;
                    });
                    item["sizeNum"] = list.join(",");
                    console.log(item);
                }
            });
        }
        emit("update:yanPiData", list);
    });
    // 获取拖拽元素
    nextTick(() => {
        robot.value = document.getElementById("gva-base-load-dom");
    });
});
</script>

<style lang="scss" scoped>
.table-form {
    .el-form-item {
        margin-bottom: 0;
        width: 80%;
    }
}

.yanpidia {
    :deep(.el-form-item__content) {
        display: unset !important;
    }

    :deep(.el-form-item) {
        margin-bottom: 0;
        margin-top: 20px;
    }
}
</style>